package com.yonyou.pmclouds.alterandvisa.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.alterandvisa.entity.VisaDemoVO;
import com.yonyou.pmclouds.alterandvisa.rmiitf.AlterAndVisaQuery;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.outter.enterprise.EnterpriseInfoQuery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 智能生成签证-演示controller
 *
 * @author 唐焕
 * @date 2018.9.11
 */
@RequestMapping("/outter/visademo")
@RestController
public class VisaDemoController {

    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private AlterAndVisaQuery query;
    @Autowired
    private EnterpriseInfoQuery enterpriseInfoQuery;

    /**
     * 查询变更签证的项目和施工单位，供演示使用
     *
     * @param pkTenant     租户
     * @param pkUser       用户
     * @param inputProject 需要匹配的项目名
     * @return
     * @throws BusinessException
     */
    @GetMapping("/getVisaDemo")
    VisaDemoVO getVisaDemo(@RequestParam(value = "pkTenant", defaultValue = "x61tnmfx", required = false) String pkTenant, @RequestParam("pkUser") String pkUser,
                           @RequestParam("inputProject") String inputProject) throws BusinessException {
        if (StringUtils.isEmpty(pkUser) || StringUtils.isEmpty(inputProject)) {
            throw new BusinessException("用户id和项目均不能为空");
        }
        VisaDemoVO result = query.getVisaDemo(pkTenant, pkUser, inputProject);
        // 获取施工单位名称
        if (!StringUtils.isEmpty(result.getPkConstructEnterprise())) {
            enterpriseInfoQuery.tranEntInfoField(new VisaDemoVO[]{result}, new String[]{VisaDemoVO.PK_CONSTRUCT_ENTERPRISE},
                    new String[]{VisaDemoVO.CONSTRUCT_ENTERPRISE_NAME});
        }
        return result;
    }

}
